
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->

<head>


<meta charset="utf-8">
<meta http-equiv="cleartype" content="on">

<title>Install Hive on Local With Mysql - Sam小龙</title>
<meta name="author" content="xiaolong.yuanxl">




<meta name="description" content="安装hive">

<meta name="keywords" content="hadoop hive ">


<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Twitter Cards -->


<!-- Open Graph -->
<meta property="og:local" content="en_US">
<meta property="og:type" content="article">
<meta property="og:url" content="http://yuanxiaolong.github.io/blog/2014/07/20/install-hive-on-local-with-mysql">
<meta property="og:title" content="install hive on local with mysql">
<meta property="og:description" content="安装hive">

  <meta property="og:image" content="">

<meta property="og:site_name" content="Sam小龙">

<link rel="canonical" href="http://yuanxiaolong.github.io/blog/2014/07/20/install-hive-on-local-with-mysql">
<link href="/favicon.png" rel="icon">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<!-- <link href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet"> -->
<link href="/stylesheets/font-awesome.min.css" rel="stylesheet">
<link href="/atom.xml" rel="alternate" title="Sam小龙" type="application/atom+xml">

<!-- the flow button on left -->
<script src="/javascripts/vendor/modernizr-2.6.2.custom.min.js"></script>


  <style type="text/css">body {background-image:url(/images/bg.jpg);background-size:cover;}</style>

<!-- 
  

  
    
  

  <style type="text/css">body {background-image:url(
      /images/
    
      bg.jpg
    
  
    );}</style>
 -->

<!--Fonts from Google"s Web font directory at http://google.com/webfonts
<link href="//fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="//fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
-->


</head>

<body id="post" >

<!--[if lt IE 9]><div class="upgrade"><strong><a href="http://whatbrowser.org/">Your browser is quite old!</strong> Why not upgrade to a different browser to better enjoy this site?</a></div><![endif]-->
<nav id="dl-menu" class="dl-menuwrapper" role="navigation">
	<button class="dl-trigger">Open Menu</button>
	<ul class="dl-menu">
		<li><a href="/">主页</a></li>

		<li>
			<a href="#">内容</a>
			<ul class="dl-submenu">
				<li><a href="/posts/">文章列表</a></li>
				<li><a href="/categories/">分类列表</a></li>
			</ul>
		</li>

		<li>
			<a href="#">关于</a>
			<ul class="dl-submenu">
				<li>
					<img src="/images/avatar.png" alt="xiaolong.yuanxl photo" class="author-photo">
					<h4>xiaolong.yuanxl</h4>
					<p></p>
				</li>
				<li><a href="/about">关于我</a></li>
				<li>
					<a href="mailto:232351936@qq.com"><i class="fa fa-envelope"></i> Email</a>
				</li>
				
				
				<li>
					<a href="http://github.com/yuanxiaolong"><i class="fa fa-github"></i> GitHub</a>
				</li>
			</ul><!-- /.dl-submenu -->
		</li>

		
	</ul><!-- /.dl-menu -->
</nav><!-- /.dl-menuwrapper -->




<div id="main" role="main" >
  <article class="hentry">
    <header class="header-title">
      <div class="header-title-wrap">
        
          <h1 class="entry-title"><a href="/blog/2014/07/20/install-hive-on-local-with-mysql/" rel="bookmark" title="install hive on local with mysql">install hive on local with mysql</a></h1>
        
        <h2>July 20, 2014</h2>
      </div><!-- /.header-title-wrap -->
    </header>
    <div class="entry-content">
      <p>介绍一下本地安装 Hive 0.13.1 ,并元数据存放到本地mysql上</p>

<!--more-->

<hr />

<h2 id="section">准备工作</h2>
<ol>
  <li>本地安装了hadoop 、mysql</li>
  <li>下载 <a href="http://mirrors.hust.edu.cn/apache/hive/stable/" target="_blank"><font color="#3756b2">apache-hive-0.13.1-bin.tar.gz</font></a></li>
</ol>

<hr />

<h2 id="section-1">开始安装</h2>
<p>1.解压 apache-hive-0.13.1-bin.tar.gz</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
</pre></td><td class="code"><pre><code class="bash"><span class="line">tar xzf ./apache-hive-0.13.1-bin.tar.gz
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>2.复制几个配置文件</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
</pre></td><td class="code"><pre><code class="bash"><span class="line">cp hive-default.xml.template hive-site.xml
</span><span class="line">cp hive-env.sh.template hive-env.sh
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>3.用vi修改这2个文件的内容</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span>hive-env.sh</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
</pre></td><td class="code"><pre><code class="bash"><span class="line"><span class="c"># Set HADOOP_HOME to point to a specific hadoop install directory</span>
</span><span class="line"><span class="nv">HADOOP_HOME</span><span class="o">=</span><span class="nv">$HADOOP_HOME</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>
<font color="#818a8b" size="3">(注:如果你的PATH下有HADOOP_HOME变量才可以这样设置，否则应该指出hadoop的安装路径)</font>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span>hive-site.xml</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
<span class="line-number">8</span>
<span class="line-number">9</span>
<span class="line-number">10</span>
<span class="line-number">11</span>
<span class="line-number">12</span>
<span class="line-number">13</span>
<span class="line-number">14</span>
<span class="line-number">15</span>
<span class="line-number">16</span>
<span class="line-number">17</span>
<span class="line-number">18</span>
<span class="line-number">19</span>
<span class="line-number">20</span>
<span class="line-number">21</span>
<span class="line-number">22</span>
<span class="line-number">23</span>
</pre></td><td class="code"><pre><code class="bash"><span class="line">&lt;property&gt;
</span><span class="line">  &lt;name&gt;javax.jdo.option.ConnectionURL&lt;/name&gt;
</span><span class="line">  &lt;value&gt;jdbc:mysql://localhost:3306/hive?characterEncoding<span class="o">=</span>UTF-8&lt;/value&gt;
</span><span class="line">  &lt;description&gt;JDBC connect string <span class="k">for </span>a JDBC metastore&lt;/description&gt;
</span><span class="line">&lt;/property&gt;
</span><span class="line">
</span><span class="line">&lt;property&gt;
</span><span class="line">  &lt;name&gt;javax.jdo.option.ConnectionDriverName&lt;/name&gt;
</span><span class="line">  &lt;value&gt;com.mysql.jdbc.Driver&lt;/value&gt;
</span><span class="line">  &lt;description&gt;Driver class name <span class="k">for </span>a JDBC metastore&lt;/description&gt;
</span><span class="line">&lt;/property&gt;
</span><span class="line">
</span><span class="line">&lt;property&gt;
</span><span class="line">  &lt;name&gt;javax.jdo.option.ConnectionUserName&lt;/name&gt;
</span><span class="line">  &lt;value&gt;hive&lt;/value&gt;
</span><span class="line">  &lt;description&gt;username to use against metastore database&lt;/description&gt;
</span><span class="line">&lt;/property&gt;
</span><span class="line">
</span><span class="line">&lt;property&gt;
</span><span class="line">  &lt;name&gt;javax.jdo.option.ConnectionPassword&lt;/name&gt;
</span><span class="line">  &lt;value&gt;hive&lt;/value&gt;
</span><span class="line">  &lt;description&gt;password to use against metastore database&lt;/description&gt;
</span><span class="line">&lt;/property&gt;
</span></code></pre></td></tr></table></div></figure></notextile></div>

<h4 id="font-color800b7e4font"><font color="#800b7e">解释一下这4个变量的意思</font></h4>
<ul>
  <li>第一个： 说明是让hive将元数据存放到mysql中，且用mysql连接串来连接</li>
  <li>第二个： 连接mysql的驱动 (<a href="http://pan.baidu.com/s/1dDnaw05" target="_blank"><font color="#3756b2">这里下载</font></a> 并把它放到hive的lib目录下)</li>
  <li>第三个： 连接mysql用户名</li>
  <li>第四个： 连接mysql密码</li>
</ul>

<p>因此，我们需要先在mysql上，新建一个用户和密码（我这里都是叫hive），同时<font color="red">用hive这个用户新建一个叫hive的数据库</font></p>

<p>然后修改mysql hive 这个数据库字符集</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
</pre></td><td class="code"><pre><code class="bash"><span class="line">alter database hive character <span class="nb">set </span>latin1<span class="p">;</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<hr />

<h2 id="hive">启动hive</h2>

<p>在hive的bin目录下执行</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
</pre></td><td class="code"><pre><code class="bash"><span class="line">sh ./hive
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>whoops~~~~报错了,如下：</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
<span class="line-number">8</span>
<span class="line-number">9</span>
<span class="line-number">10</span>
<span class="line-number">11</span>
<span class="line-number">12</span>
<span class="line-number">13</span>
</pre></td><td class="code"><pre><code class="bash"><span class="line">xiaolongyuan@xiaolongdeMacBook-Air bin<span class="nv">$ </span>./hive
</span><span class="line">Exception in thread <span class="s2">&quot;main&quot;</span> java.lang.NoClassDefFoundError: org/apache/hadoop/hive/conf/HiveConf
</span><span class="line">	at java.lang.Class.forName0<span class="o">(</span>Native Method<span class="o">)</span>
</span><span class="line">	at java.lang.Class.forName<span class="o">(</span>Class.java:270<span class="o">)</span>
</span><span class="line">	at org.apache.hadoop.util.RunJar.main<span class="o">(</span>RunJar.java:153<span class="o">)</span>
</span><span class="line">Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hive.conf.HiveConf
</span><span class="line">	at java.net.URLClassLoader<span class="nv">$1</span>.run<span class="o">(</span>URLClassLoader.java:366<span class="o">)</span>
</span><span class="line">	at java.net.URLClassLoader<span class="nv">$1</span>.run<span class="o">(</span>URLClassLoader.java:355<span class="o">)</span>
</span><span class="line">	at java.security.AccessController.doPrivileged<span class="o">(</span>Native Method<span class="o">)</span>
</span><span class="line">	at java.net.URLClassLoader.findClass<span class="o">(</span>URLClassLoader.java:354<span class="o">)</span>
</span><span class="line">	at java.lang.ClassLoader.loadClass<span class="o">(</span>ClassLoader.java:425<span class="o">)</span>
</span><span class="line">	at java.lang.ClassLoader.loadClass<span class="o">(</span>ClassLoader.java:358<span class="o">)</span>
</span><span class="line">	... 3 more
</span></code></pre></td></tr></table></div></figure></notextile></div>

<font color="#e14a40">解决方法: </font>

<p>修改你的Hadoop配置hadoop-env.sh，在后面加上 <em><font color="green">$HADOOP_CLASSHPATH</font></em></p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span>hadoop-env.sh</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
</pre></td><td class="code"><pre><code class="bash"><span class="line"><span class="c"># Extra Java CLASSPATH elements.  Optional.</span>
</span><span class="line"><span class="nb">export </span><span class="nv">HADOOP_CLASSPATH</span><span class="o">=</span>.:<span class="nv">$HADOOP_CLASSPATH</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>再次运行，whoops~~~又报错了。。。</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
</pre></td><td class="code"><pre><code class="bash"><span class="line">Caused by: MetaException<span class="o">(</span>message:Got exception: java.net.ConnectException Call to
</span><span class="line">localhost/127.0.0.1:9000 failed on connection exception: java.net.ConnectException:
</span><span class="line"> Connection refused<span class="o">)</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>这次因为由于Hadoop没有启动,启动hadoop即可。然后再次运行hive，既可以成功。</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
<span class="line-number">8</span>
<span class="line-number">9</span>
</pre></td><td class="code"><pre><code class="bash"><span class="line">xiaolongyuan@xiaolongdeMacBook-Air bin<span class="nv">$ </span>./hive
</span><span class="line">14/07/20 01:38:56 WARN conf.HiveConf: DEPRECATED: hive.metastore.ds.retry.* no longer has any effect.  Use hive.hmshandler.retry.* instead
</span><span class="line">
</span><span class="line">Logging initialized using configuration in jar:file:/Users/xiaolongyuan/Documents/hive-0.13.1/lib/hive-common-0.13.1.jar!/hive-log4j.properties
</span><span class="line">hive&gt; show databases<span class="p">;</span>
</span><span class="line">OK
</span><span class="line">default
</span><span class="line">Time taken: 0.73 seconds, Fetched: 1 row<span class="o">(</span>s<span class="o">)</span>
</span><span class="line">hive&gt;
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>我们还可以看到hive的元数据已经存到Mysql里了
<img src="/images/hadoop/hive-local-mysql.png" alt="hive-metadata-mysql" /></p>


      <!-- add copyright for each post -->
      <div style="margin-top:20px;">
        <font color="gray" size="3">
          原文地址，转载请注明出处:<br/>
          <a href="http://blog.yuanxiaolong.cn/blog/2014/07/20/install-hive-on-local-with-mysql/">http://blog.yuanxiaolong.cn/blog/2014/07/20/install-hive-on-local-with-mysql/</a>
        </font>
      </div>
      <footer class="entry-meta">
        <span class="entry-tags"><a href="/categories/#hadoop" title="Pages tagged hadoop" class="tag">hadoop</a><a href="/categories/#hive" title="Pages tagged hive" class="tag">hive</a></span>
        <span><a href="/blog/2014/07/20/install-hive-on-local-with-mysql/" rel="bookmark" title="install hive on local with mysql">install hive on local with mysql</a> was published on <span class="entry-date date published updated"><time datetime="2014-07-20T01:40:49+08:00">July 20, 2014</time></span></span>
        
        <span class="author vcard"><span class="fn"><a href="" title="About xiaolong.yuanxl">xiaolong.yuanxl</a></span></span>
        <div class="social-share">
          <div class="socialcount socialcount-small inline-list">
            <!-- <li class="facebook"><a href="https://www.facebook.com/sharer/sharer.php?u=/blog/2014/07/20/install-hive-on-local-with-mysql/" title="Share on Facebook"><span class="count"><i class="fa fa-facebook-square"></i> Like</span></a></li>
            <li class="twitter"><a href="https://twitter.com/intent/tweet?text=/blog/2014/07/20/install-hive-on-local-with-mysql/" title="Share on Twitter"><span class="count"><i class="fa fa-twitter-square"></i> Tweet</span></a></li>
            <li class="googleplus"><a href="https://plus.google.com/share?url=/blog/2014/07/20/install-hive-on-local-with-mysql/" title="Share on Google Plus"><span class="count"><i class="fa fa-google-plus-square"></i> +1</span></a></li> -->
            <!-- 多说评论框 start -->
          	<div class="ds-thread" data-thread-key="/blog/2014/07/20/install-hive-on-local-with-mysql/" data-title="install hive on local with mysql" data-url="http://blog.yuanxiaolong.cn/blog/2014/07/20/install-hive-on-local-with-mysql/"></div>
            <!-- 多说评论框 end -->
            <!-- 多说公共JS代码 start (一个网页只需插入一次) -->
            <script type="text/javascript">
            var duoshuoQuery = {short_name:"yuanxiaolong"};
            	(function() {
            		var ds = document.createElement('script');
            		ds.type = 'text/javascript';ds.async = true;
            		ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
            		ds.charset = 'UTF-8';
            		(document.getElementsByTagName('head')[0]
            		 || document.getElementsByTagName('body')[0]).appendChild(ds);
            	})();
            	</script>
            <!-- 多说公共JS代码 end -->
        </div>
        </div><!-- /.social-share -->
      </footer>

    </div><!-- /.entry-content -->
    
      <div class="read-more">
        
          <div class="read-more-header">
            <a href="/blog/2014/09/07/install-nfs-and-share-file/" class="btn">Read More</a>
          </div><!-- /.read-more-header -->
          <div class="read-more-content">
            <h3><a href="/blog/2014/09/07/install-nfs-and-share-file/" title="install nfs and shshare file">install nfs and shshare file</a></h3>
            <p>安装nfs服务器，用于共享配置 <a href="/blog/2014/09/07/install-nfs-and-share-file/"> Continue reading</a></p>
          </div><!-- /.read-more-content -->
        
        <div class="read-more-list">
          
            <div class="list-item">
              <h4><a href="/blog/2014/09/07/install-dns-server-bind/" title="install dns server bind">install dns server bind</a></h4>
              <span>Published on September 07, 2014</span>
            </div><!-- /.list-item -->
          
            <div class="list-item">
              <h4><a href="/blog/2014/08/31/analysis-hadoop-load-configuration/" title="analysis hadoop load configuration">analysis hadoop load configuration</a></h4>
              <span>Published on August 31, 2014</span>
            </div><!-- /.list-item -->
          
        </div><!-- /.read-more-list -->
      </div><!-- /.read-more -->
    
    
  </article>
</div><!-- /#main -->

<div class="footer-wrapper">
  <footer role="contentinfo">
    <span>&copy; 2014 xiaolong.yuanxl. Powered by <a href="http://octopress.org">Octopress</a> using the <a href="https://github.com/Z1MM32M4N/hpstr-theme/">HPSTR Theme for Octopress</a>.</span>

  </footer>
</div><!-- /.footer-wrapper -->



<script src="http://cdn.staticfile.org/jquery/1.9.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="/javascripts/vendor/jquery-1.9.1.min.js"><\/script>')</script>
<!--
<script src="/javascripts/octopress.js" type="text/javascript"></script>
-->
<script src="/javascripts/scripts.min.js"></script>
<!-- 
 -->
<script type="text/javascript" src="http://tajs.qq.com/stats?sId=35560703" charset="UTF-8"></script>






</body>
</html>
